package com.leyou.common.exception.controller;

import com.leyou.common.exception.pojo.ExceptionResult;
import com.leyou.common.exception.pojo.LyException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * 乐优全局控制异常拦截器
 * @author ycs
 */
@ControllerAdvice
public class LyExceptionController {
    /**
     * 当有异常会进入这个方法指定自定义异常的class对象
     * @return
     */
    @ExceptionHandler(LyException.class)
    public ResponseEntity<ExceptionResult>handlerLyException(LyException e){
        //返回异常信息
        return ResponseEntity.status(e.getStatus()).body(new ExceptionResult(e));
    }
}
